<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org"
      th:replace="~{admin/layout :: html(title=${title}, content=~{::content})}">
<head>
    <title>新闻管理</title>
</head>
<body>
    <div th:fragment="content">
        <div th:if="${message}" class="alert alert-success" th:text="${message}"></div>
        <div th:if="${error}" class="alert alert-danger" th:text="${error}"></div>

        <a href="/admin/news/add" class="btn btn-primary mb-3"><i class="fas fa-plus"></i> 添加新新闻</a>
        
        <table class="table table-striped">
            <thead>
                <tr>
                    <th>ID</th>
                    <th>标题</th>
                    <th>类型</th>
                    <th>作者</th>
                    <th>状态</th>
                    <th>发布时间</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>
                <tr th:each="news : ${newsList}">
                    <td th:text="${news.id}"></td>
                    <td th:text="${#strings.abbreviate(news.title, 30)}"></td>
                    <td th:text="${news.type}"></td>
                    <td th:text="${news.author}"></td>
                    <td th:text="${news.status}"></td>
                    <td th:text="${#temporals.format(news.createTime, 'yyyy-MM-dd')}"></td>
                    <td>
                        <a th:href="@{/admin/news/edit/{id}(id=${news.id})}" class="btn btn-sm btn-warning"><i class="fas fa-edit"></i></a>
                        <a th:href="@{/admin/news/delete/{id}(id=${news.id})}" class="btn btn-sm btn-danger"
                           onclick="return confirm('确定要删除这篇新闻吗？');"><i class="fas fa-trash"></i></a>
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</body>
</html> 